home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWExcLib / Sources / FWAutoDe.cpp next >
Encoding:
Text File  |  1995-11-08  |  5.4 KB  |  155 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWAutoDe.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFound.hpp"
  11.  
  12. #ifndef   FWAUTODE_H
  13. #include "FWAutoDe.h"
  14. #endif
  15.  
  16. #if defined(FW_USE_NEW_HELPER) && !defined(FWNEWHEL_H)
  17. #include "FWNewHel.h"
  18. #endif
  19.  
  20. #ifndef FWEXCTAS_H
  21. #include "FWExcTas.h"
  22. #endif
  23.  
  24. #ifndef FWPRIDEB_H
  25. #include "FWPriDeb.h"
  26. #endif
  27.  
  28. #if FW_LIB_EXPORT_PRAGMAS
  29. #pragma lib_export on
  30. #endif
  31.  
  32. #ifdef FW_BUILD_MAC
  33. #pragma segment FWExcLib
  34. #endif
  35.  
  36. #if defined(FW_BUILD_WIN) && !defined(FW_qUsePlatformAlloc)
  37. #define FW_qUsePlatformAlloc
  38. #endif
  39.  
  40. //========================================================================================
  41. // CLASS _FW_CAutoDestructObject
  42. //========================================================================================
  43.  
  44. #if defined(__BORLANDC__) && !defined(FW_NATIVE_EXCEPTIONS)
  45. //----------------------------------------------------------------------------------------
  46. // _FW_CAutoDestructObject::__Delete
  47. //----------------------------------------------------------------------------------------
  48. void _FW_CAutoDestructObject::__Delete()
  49. {
  50.     // Borland C++ 3.1 is bizzare, too.  It will call operator delete in any case, but
  51.     //    not intentionally, but simply because it forgets to push the argument for
  52.     //    the destructor on the stack
  53.     __asm {
  54.         push    0                        // this is the argument that the compiler forgets
  55.         push    word ptr[this + 2]        // push the address
  56.         push    word ptr[this]
  57.         les        bx, [this]                // get the object pointer
  58.         les        bx, dword ptr es:[bx]    // get the vtable pointer
  59.         call    dword ptr es:[bx]        // and call the dtor
  60.         add        sp, 6                    // clean up the stack
  61.     };
  62. }
  63. #endif    
  64.  
  65. //----------------------------------------------------------------------------------------
  66. // _FW_CAutoDestructObject::~_FW_CAutoDestructObject
  67. //----------------------------------------------------------------------------------------
  68. _FW_CAutoDestructObject::~_FW_CAutoDestructObject()
  69. {
  70. }
  71.  
  72. #ifdef FW_USE_NEW_HELPER    
  73. //----------------------------------------------------------------------------------------
  74. // _FW_CAutoDestructObject::operator new
  75. //----------------------------------------------------------------------------------------
  76. void* _FW_CAutoDestructObject::operator new(size_t size, const FW_CPrivNewHelper &helper)
  77. {
  78. #ifdef FW_qUsePlatformAlloc
  79.     void *p = ::operator new(size);
  80. #else
  81.     FW_PRIV_ASSERT(helper.fNewHandler != NULL);
  82.     FW_PRIV_ASSERT(helper.fDeleteHandler != NULL);
  83.  
  84.     if (GetOperatorNewHandler() == NULL)
  85.     {
  86.         SetOperatorNewHandler(helper.fNewHandler);
  87.         SetOperatorDeleteHandler(helper.fDeleteHandler);
  88.     }
  89.     FW_PRIV_ASSERT(helper.fNewHandler == GetOperatorNewHandler());
  90.     FW_PRIV_ASSERT(helper.fDeleteHandler == GetOperatorDeleteHandler());
  91.     __FW_OperatorNewHandler operatorNewHandler = helper.fNewHandler;
  92.     void *p = operatorNewHandler(size);
  93. #endif
  94.     
  95.     helper.WatchObject((_FW_CAutoDestructObject*)p, size);
  96.     
  97.     return p;
  98. }
  99. #endif
  100.  
  101. #ifdef FW_USE_NEW_HELPER    
  102. //----------------------------------------------------------------------------------------
  103. // _FW_CAutoDestructObject::operator delete
  104. //----------------------------------------------------------------------------------------
  105. void _FW_CAutoDestructObject::operator delete(void *object)
  106. {
  107. #ifdef FW_qUsePlatformAlloc
  108.     ::operator delete(object);
  109. #else
  110.     __FW_OperatorDeleteHandler operatorDeleteHandler = GetOperatorDeleteHandler();
  111.     FW_PRIV_ASSERT(operatorDeleteHandler != NULL);
  112.     operatorDeleteHandler(object);
  113. #endif
  114. }
  115. #endif
  116.  
  117. //----------------------------------------------------------------------------------------
  118. // _FW_CAutoDestructObject::SetOperatorNewHandler
  119. //----------------------------------------------------------------------------------------
  120. void _FW_CAutoDestructObject::SetOperatorNewHandler(__FW_OperatorNewHandler operatorNewHandler)
  121. {
  122.     FW_SPrivExceptionGlobals& globals = FW_CExceptionTaskGlobals::GetExceptionGlobals();
  123.     FW_PRIV_ASSERT(globals.gOperatorNewHandler == NULL);
  124.     globals.gOperatorNewHandler = operatorNewHandler;
  125. }
  126.  
  127.  
  128. //----------------------------------------------------------------------------------------
  129. // _FW_CAutoDestructObject::SetOperatorDeleteHandler
  130. //----------------------------------------------------------------------------------------
  131.  
  132. void _FW_CAutoDestructObject::SetOperatorDeleteHandler(__FW_OperatorDeleteHandler operatorDeleteHandler)
  133. {
  134.     FW_SPrivExceptionGlobals& globals = FW_CExceptionTaskGlobals::GetExceptionGlobals();
  135.     FW_PRIV_ASSERT(globals.gOperatorDeleteHandler == NULL);
  136.     globals.gOperatorDeleteHandler = operatorDeleteHandler;
  137. }
  138.  
  139. //----------------------------------------------------------------------------------------
  140. // _FW_CAutoDestructObject::GetOperatorNewHandler
  141. //----------------------------------------------------------------------------------------
  142. __FW_OperatorNewHandler _FW_CAutoDestructObject::GetOperatorNewHandler()
  143. {
  144.     return FW_CExceptionTaskGlobals::GetExceptionGlobals().gOperatorNewHandler;
  145. }
  146.  
  147. //----------------------------------------------------------------------------------------
  148. // _FW_CAutoDestructObject::GetOperatorDeleteHandler
  149. //----------------------------------------------------------------------------------------
  150.  
  151. __FW_OperatorDeleteHandler _FW_CAutoDestructObject::GetOperatorDeleteHandler()
  152. {
  153.     return FW_CExceptionTaskGlobals::GetExceptionGlobals().gOperatorDeleteHandler;
  154. }
  155.